package com.yztc.orangeentertainment.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.yztc.orangeentertainment.R;
import com.yztc.orangeentertainment.base.OnItemClickListener;
import com.yztc.orangeentertainment.bean.channalarticle.ChannalArticleTagsBean;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by My on 2016/10/10.
 */
public class ChannalArticleTuiJianAdapter extends RecyclerView
        .Adapter<ChannalArticleTuiJianAdapter.MyViewHolder> {
    private Context context;
    private List<ChannalArticleTagsBean> tagsBeanList;
    private OnItemClickListener onItemClickListener;

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    public ChannalArticleTuiJianAdapter(Context context, List<ChannalArticleTagsBean> tagsBeanList) {
        this.context = context;
        this.tagsBeanList = tagsBeanList;
    }

    public Context getContext() {
        return context;
    }

    public void setContext(Context context) {
        this.context = context;
    }

    public List<ChannalArticleTagsBean> getTagsBeanList() {
        return tagsBeanList;
    }

    public void setTagsBeanList(List<ChannalArticleTagsBean> tagsBeanList) {
        this.tagsBeanList = tagsBeanList;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.channalarticletuijian_item,
                parent, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(final MyViewHolder holder, int position) {
        holder.sdArticletuijianitem.setImageURI(tagsBeanList.get(position).getImg());
        holder.tvArticletuijianitemtitle.setText(tagsBeanList.get(position).getName());
        if (onItemClickListener != null) {
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int pos = holder.getLayoutPosition();
                    onItemClickListener.onItemClick(holder.itemView, pos);
                }
            });

            holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    int pos = holder.getLayoutPosition();
                    onItemClickListener.onItemLongClick(holder.itemView, pos);
                    return false;
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return tagsBeanList.size();
    }

    static class MyViewHolder extends RecyclerView.ViewHolder {
        @InjectView(R.id.sd_articletuijianitem)
        SimpleDraweeView sdArticletuijianitem;
        @InjectView(R.id.tv_articletuijianitemtitle)
        TextView tvArticletuijianitemtitle;
        public MyViewHolder(View itemView) {
            super(itemView);
            ButterKnife.inject(this, itemView);
        }
    }
}
